package com.yihaodian.index.meta.shard.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class ZkShardConfig implements ShardConfig {

	private int version = 0;	
	
	private List<ShardRule> rules;
	
	public int getVersion() {		
		return 0;
	}
	
	public void setVersion(int version) {
		this.version = version;
	}


	public void setRules(List<ShardRule> rules) {
		this.rules = rules;
	}


	public List<ShardRule> getRules() {	
		return rules;
	}
	
	/**
	 * Generate zk data like: 
	 *    { path : content }
	 * @return
	 */
	public Map<String, Byte[]> toZkData(){
		Map<String, Byte[]> map = new HashMap<String, Byte[]>();
		
		if(rules != null) {
			for(ShardRule rule : rules) {
				Map<String, Byte[]> rmap = toZkData(rule);
				if(rmap != null) {
					map.putAll(rmap);
				}
			}
		}		
		return map;
	}
	
	protected abstract Map<String, Byte[]> toZkData(ShardRule rule);

}
